package com.qyhl.webtv.module_news.news.union.special.detail;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.SpecialDetailBean;
import com.qyhl.webtv.commonlib.entity.news.UnionBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

/**
 * Created by qyhl on 2017/12/4.
 */

public class SpecialDetailModel implements SpecialDetailContract.SpecialDetailModel {
    private SpecialDetailPresenter mPresenter;

    public SpecialDetailModel(SpecialDetailPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取子栏目列表
     *
     * @param sectionId
     */
    @Override
    public void getSecitons(String sectionId) {

        EasyHttp.get(NewsUrl.GET_TOWN_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("type", "1")
                .params("setions", sectionId)
                .execute(new SimpleCallBack<List<UnionBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError(2, "暂无任何内容！");
                        } else {
                            mPresenter.setError(1, "解析出错，加载失败！");
                        }
                    }

                    @Override
                    public void onSuccess(List<UnionBean> unionBeans) {
                        if (unionBeans != null && unionBeans.size() > 0) {
                            mPresenter.setSection(unionBeans);
                        } else {
                            mPresenter.setError(2, "暂无任何内容！");
                        }
                    }
                });

    }

    /**
     * 获取推荐新闻内容
     *
     * @param sectionId
     */
    @Override
    public void getDatas(String sectionId) {

        EasyHttp.get(NewsUrl.GET_SPECIAL)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("sections", sectionId)
                .execute(new SimpleCallBack<List<SpecialDetailBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError(2, "暂无任何内容！");
                        } else {
                            mPresenter.setError(1, "解析出错，加载失败！");
                        }
                    }

                    @Override
                    public void onSuccess(List<SpecialDetailBean> specialDetailBeans) {
                        if (specialDetailBeans != null && specialDetailBeans.size() > 0) {
                            mPresenter.setDatas(specialDetailBeans);
                        } else {
                            mPresenter.setError(2, "暂无任何内容！");
                        }
                    }
                });



    }
}
